package com.example.blog.dao;

import com.example.blog.pojo.tag;
import com.example.blog.pojo.type;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

@Component
@Mapper
public interface tagRepository {

    @Select("select * from blog.tag where id = #{id}")
    public tag findById(Integer id);

    @Select("select * from blog.tag where name = #{name}")
    public tag findByName(String name);

    @Insert("insert into blog.tag (id,name) values (#{id},#{name})")
    void save(tag tag);

    @Select("select * from blog.tag")
    Page<tag> findAll();

    @Select("SELECT tag.* , COUNT(tag_id) AS 'tagCount' FROM tag,blog_tag WHERE tag.id = tag_id GROUP BY tag_id")
    Page<tag> find();

    @Delete("delete from blog.tag where id = #{id}")
    void delete(Integer id);

    @Select("select count(*) from blog.tag")
    Integer count();

    @Update("update blog.tag set name=#{name} where id=#{id}")
    void update(Integer id, String name);
}
